﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.IO;
using System.Collections;

namespace CookeryBook
{
    public partial class FormRecipe : Form
    {
        String lineConnection;
        OleDbConnection connec;
        FormSelectIng formSelectIng;
        OleDbDataReader astr_glResult;
        ArrayList sequence = new ArrayList();

        public FormRecipe()
        {
            lineConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Environment.CurrentDirectory + "\\cuisine.accdb";
            connec = new OleDbConnection(lineConnection); 
            formSelectIng = new FormSelectIng(lineConnection);
            InitializeComponent();
        }

        public void test()
        {
        }

        private void FormRecipe_Load(object sender, EventArgs e)
        {
            // TODO: cette ligne de code charge les données dans la table 'cuisineDataSet.recette'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
            //this.recetteTableAdapter.Fill(this.cuisineDataSet.recette);
            void_piGetRecipeName("");
        }

        private void txt_image_Click(object sender, EventArgs e)
        {
            openFileDialogImage.ShowDialog();
        }

        private void openFileDialogImage_FileOk(object sender, CancelEventArgs e)
        {
            txt_image.Text = openFileDialogImage.FileName;
        }

        private void btn_ajoutIng_Click(object sender, EventArgs e)
        {
            formSelectIng.ShowDialog();
        }

        private void dtg_Recipes_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            Int32 ui_bcIdRow = e.RowIndex;

            tb_nom.Text = dtg_Recipes.Rows[ui_bcIdRow].Cells[1].Value.ToString();
            tb_description.Text = dtg_Recipes.Rows[ui_bcIdRow].Cells[3].Value.ToString();

        }

        private void tb_search_TextChanged(object sender, EventArgs e)
        {
            void_piGetRecipeName(tb_search.Text);
        }

#region Fonctions de BDD

        private void void_piGetRecipeName(String str_roName)
        {
            OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Environment.CurrentDirectory + "\\cuisine.accdb");

            con.Open();

            OleDbDataAdapter da = new OleDbDataAdapter("select * from recette where nom like '%" + str_roName + "%';", con);

            DataSet ds = new DataSet();

            da.Fill(ds, "recette");

            DataTable dt = ds.Tables[0];

            dtg_Recipes.DataSource = dt;
        }
#endregion









































    }

}
